package com.heima.wemedia.controller.v1;

import com.heima.model.admin.dtos.AdChannelDto;
import com.heima.model.admin.pojos.AdChannel;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.pojos.WmChannel;
import com.heima.wemedia.service.WmChannelService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("/api/v1/channel")
public class ChannelController {

    @Resource
    private WmChannelService wmChannelService;

    @GetMapping("/channels")
    public ResponseResult channel() {
        List<WmChannel> channels = wmChannelService.list();
        return ResponseResult.okResult(channels);
    }

    @GetMapping("/del/{id}")
    public ResponseResult deleteChannelById(@PathVariable("id") Integer id) {
        return wmChannelService.deleteChannelById(id);
    }

    @PostMapping("/list")
    public ResponseResult findChannelsByName(@RequestBody @Valid AdChannelDto dto) {
        return wmChannelService.findChannelsByName(dto);
    }

    @PostMapping("/save")

    public ResponseResult saveChannel(@RequestBody @Valid AdChannel adChannel){

        return wmChannelService.saveChannel(adChannel);
    }

    @PostMapping("/update")
    public ResponseResult updateChannelById(@RequestBody @Valid AdChannel adChannel){

        return wmChannelService.updateChannelById(adChannel);
    }


}
